package com.offcn.service.impl;

import com.offcn.entity.Product;
import com.offcn.entity.ProductExample;
import com.offcn.mapper.ProductMapper;
import com.offcn.service.ProductService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Service("productService")
public class ProductServiceImpl  implements ProductService {
    @Resource
    private ProductMapper productMapper;
    @Override
    public List<Product> findThirdProduct(int thirdId) {
        ProductExample example=new ProductExample();
        ProductExample.Criteria criteria = example.createCriteria();
        criteria.andCategorylevel3idEqualTo(thirdId);
        return productMapper.selectByExample(example);
    }

    @Override
    public List<Product> findAllProduct() {
        List<Product>list = new ArrayList<Product>();
       List<Product> productList=  productMapper.selectByExample(new ProductExample());
         if(productList !=null && productList.size()>0){
               for(int i=0;i<productList.size();i++){
                   if(i<2){
                       list.add(productList.get(i));
                   }
               }
         }

        return list;
    }

    @Override
    public Product findProductById(int id) {
        ProductExample example=new ProductExample();
        ProductExample.Criteria criteria = example.createCriteria();
        criteria.andIdEqualTo(id);
        List<Product> list = productMapper.selectByExample(example);
        return list.size()>0?list.get(0):null;
    }

    @Override
    public List<Product> selectAllById(Object[] ids) {
        return productMapper.selectAllById(ids);
    }
}
